<?php echo $this->render('/manage/header.phtml');?>
<style>
	#title, #keywords, #coverimage {
		width: 600px;
	}</style>
<link rel="stylesheet"
	href="<?php echo APPLICATION_PUBLIC_PATH;?>/kindeditor/themes/default/default.css" />
<script type="text/javascript" charset="utf-8" src="<?php echo APPLICATION_PUBLIC_PATH;?>/kindeditor/kindeditor-min.js"></script>
<script charset="utf-8" src="<?php echo APPLICATION_PUBLIC_PATH;?>/kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript">
var editor1;
var editor2;
var editor3;
$(function() {
    //实例化编辑器
	KindEditor.ready(function(K) {
		editor1 = K.create('#editor1', {
			allowFileManager : true
		});
	});
	KindEditor.ready(function(K) {
		editor2 = K.create('#editor2', {
			allowFileManager : true
		});
	});
	KindEditor.ready(function(K) {
		editor3 = K.create('#editor3', {
			allowFileManager : true
		});
	});
});
</script>
</head>
<body>
	<div id="body-wrapper">
		<?php echo $this->render('/manage/sidebar.phtml');?>
		<div id="main-content">
			<h2><?php echo $this->id == 0 ? "添加模特" : "编辑模特";?></h2>
			<div class="clear"></div>
			<div class="content-box">
				<div class="content-box-header">
					<h3>Content box</h3>
					<div class="clear"></div>
				</div>
				<div class="content-box-content">
					<?php
					$modelTypeTable = Zend_Registry::get('database')->modeltype;
					$modelListTable = Zend_Registry::get('database')->modellist;
					$modelType = $this->modelType;
					$model = $this->model;
					?>
					<div style="color: red;">
						<?php
						$result = $this->result;
						if (!empty($result)) {
							echo $result['errormsg'];
						}
						?>
					</div>
					<form action="" method="post" enctype="multipart/form-data">
						<p>
							模特ID：<?php echo $model[$modelListTable->id];?><input type="hidden" name="<?php echo $modelListTable->id;?>" value="<?php echo $model[$modelListTable->id];?>">
							<br />
							模特姓名：
							<input id="<?php echo $modelListTable->name;?>" type="text" size="18" name="name" value="<?php echo $model[$modelListTable->name];?>" />
							<br />
							模特描述（中文）：
							<br />
							<textarea id="editor1" name="<?php echo $modelListTable->description1;?>" style="width:1000px;height:250px;visibility:hidden;"><?php echo $model[$modelListTable->description1];?></textarea>
							<br />
							模特描述（英文）：
							<br />
							<textarea id="editor2" name="<?php echo $modelListTable->description2;?>" style="width:1000px;height:250px;visibility:hidden;"><?php echo $model[$modelListTable->description2];?></textarea>
							<br />
							模特描述（葡语）：
							<br />
							<textarea id="editor3" name="<?php echo $modelListTable->description3;?>" style="width:1000px;height:250px;visibility:hidden;"><?php echo $model[$modelListTable->description3];?></textarea>
							<br />
							<?php 
							$length = 0;
							$pictures = unserialize($model[$modelListTable->pictures]);
							if ($pictures) {
							?>
							模特的封面照片：
							<br />
							<img src="<?php
							echo $pictures[$model[$modelListTable->coverimage]];?>" />
							<br />
							<?php 
							}
							?>
							模特照片：
							<br />
							<div id="pictures">
							<?php 
							if ($pictures) {
							$length = count($model[$modelListTable->pictures]);
							foreach ($pictures as $picture) {
							?>
							<div class="existPicture">
							<img src="<?php
							echo $picture;?>" width="200" />
							是否设为封面
							<input type="radio" name="<?php echo $modelListTable->coverimage;?>" value="<?php
							echo $picture;?>" <?php 
							if ($pictures[$model[$modelListTable->coverimage]] == $picture) {
							    echo 'checked="checked"';
							}
							?>>
							<input type="hidden" name="existpics[]" value="<?php
							echo $picture;?>">
							<a href="###" class="deletePics">删除这张照片</a>
							<br />
							</div>
							<?php 
							}
							}
							?>
							<br />
							<br />
								<input name="<?php 
								echo $modelListTable->pictures;
								?>[]" type="file" />是否设为封面<input type="radio" name="<?php 
								echo $modelListTable->coverimage;
								?>" value="0" 
								<?php 
								if ($length == 0) {
								    echo 'checked="checked"';
								}
								?>>
								<br />
							</div>
							<input id="addPicture" type="button" value="添加一张图片" />
							<br />
							<br />
							<br />
							模特类型：
							<select id="author" name="<?php echo $modelListTable->type;?>" >
								<?php
								foreach ($modelType as $type) {
									if ($type[$modelTypeTable->id] == $model[$modelListTable->type]) {
										$selected = 'selected="selected"';
									} else {
										$selected = '';
									}
								?>
								<option <?php echo $selected;?> value="<?php echo $type[$modelTypeTable->id];?>"><?php echo $type[$modelTypeTable->name];?></option>
								<?php }?>
							</select>
							<br />
							是否显示：
							<input name="<?php echo $modelListTable->display;?>" type="checkbox" <?php echo $model[$modelListTable->display] == 1 ? 'checked' : '';?>
							>
							<br />
							<input name="submit" type="submit" value="确定" />
					</form>
				</div>
			</div>
			<?php echo $this->render('/manage/footer.phtml');?>
		</div>
	</div>
	<script type="text/javascript">
    <!--
	var count = 1;
	$(function(){
		$('#addPicture').click(function(){
			$('#pictures').append('<input name="<?php echo $modelListTable->pictures;?>[]" type="file" />是否设为封面<input type="radio" name="<?php echo $modelListTable->coverimage;?>" value="' + count + '" ><br />');
		    count++;
	    });
	    $('.deletePics').click(function(){
		    $(this).parent('.existPicture').remove();
		});
    });
    //-->
	</script>
</body>
</html>